package com.ymatou.iapi.m.couponservice.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.m.couponservice.parameter.CouponCount;
import com.ymatou.iapi.m.couponservice.parameter.GetUserWillExpireCouponCountBean;
import com.ymatou.iapi.m.couponservice.service.GetUserWillExpireCouponCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
/**
*获取用户即将过期的优惠券数量
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserWillExpireCouponCount{
	private static GetUserWillExpireCouponCountBean getuserwillexpirecouponcountBean;
	private static GetUserWillExpireCouponCountCall getuserwillexpirecouponcountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户即将过期的优惠券数量");
	}

	@Before
	public void caseUp() {
		getuserwillexpirecouponcountBean=new GetUserWillExpireCouponCountBean();
		getuserwillexpirecouponcountCall=new GetUserWillExpireCouponCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserwillexpirecouponcountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_001() {
		Logger.start(true,"获取用户即将过期的优惠券数量");
		try {
			
			getuserwillexpirecouponcountBean.setDays(11);
			getuserwillexpirecouponcountBean.setPageSize(10);
		
			List<Map> result = new YmtCouponBatchWapper().getUserWillExpireCouponCount(getuserwillexpirecouponcountBean.getPageSize(),getuserwillexpirecouponcountBean.getDays(),getuserwillexpirecouponcountBean.getLastUserId());
			
			if(result.size()>3)
			{
				getuserwillexpirecouponcountBean.setLastUserId(Integer.parseInt(result.get(1).get("UserId").toString()));
			
				getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
				getuserwillexpirecouponcountCall.callService();		
				
				verifyReturn();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_002() {
		Logger.start(true,"获取用户即将过期的优惠券数量-LastUserId空");
		try {
			
			getuserwillexpirecouponcountBean.setDays(10);
//			getuserwillexpirecouponcountBean.setLastUserId(userId);
			getuserwillexpirecouponcountBean.setPageSize(10);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
			verifyReturn();
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_003() {
		Logger.start(true,"获取用户即将过期的优惠券数量-验证pagesize");
		try {
			
			getuserwillexpirecouponcountBean.setDays(10);
			getuserwillexpirecouponcountBean.setPageSize(1);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
			verifyReturn();
		
			List<CouponCount> couponCountList = getuserwillexpirecouponcountCall.getCouponCountList().getCouponCountList();
			
			Logger.verifyEquals(1, couponCountList.size(), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_004() {
		Logger.start(true,"获取用户即将过期的优惠券数量-验证pagesize空");
		try {
			
			getuserwillexpirecouponcountBean.setDays(10);
//			getuserwillexpirecouponcountBean.setPageSize(1);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
		
			Logger.verifyEquals("0", getuserwillexpirecouponcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserwillexpirecouponcountCall.getMessage(), "验证返回Message");
		
			List<CouponCount> couponCountList = getuserwillexpirecouponcountCall.getCouponCountList().getCouponCountList();
			
			Logger.verifyEquals(0, couponCountList.size(), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_005() {
		Logger.start(true,"获取用户即将过期的优惠券数量-验证Days空");
		try {
			
//			getuserwillexpirecouponcountBean.setDays(10);
			getuserwillexpirecouponcountBean.setPageSize(1);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
		
			Logger.verifyEquals("0", getuserwillexpirecouponcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserwillexpirecouponcountCall.getMessage(), "验证返回Message");
		
			List<CouponCount> couponCountList = getuserwillexpirecouponcountCall.getCouponCountList().getCouponCountList();
			
			Logger.verifyEquals(0, couponCountList.size(), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_006() {
		Logger.start(true,"获取用户即将过期的优惠券数量-验证Days负数");
		try {
			
			getuserwillexpirecouponcountBean.setDays(-10);
			getuserwillexpirecouponcountBean.setPageSize(1);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
		
			Logger.verifyEquals("0", getuserwillexpirecouponcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserwillexpirecouponcountCall.getMessage(), "验证返回Message");
		
			List<CouponCount> couponCountList = getuserwillexpirecouponcountCall.getCouponCountList().getCouponCountList();
			
			Logger.verifyEquals(0, couponCountList.size(), "验证返回code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_007() {
		Logger.start(true,"获取用户即将过期的优惠券数量-验证PageSize负数");
		try {
			
			getuserwillexpirecouponcountBean.setDays(10);
			getuserwillexpirecouponcountBean.setPageSize(-11);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
		
			Logger.verifyEquals("3", getuserwillexpirecouponcountCall.getCode(), "验证返回code");
			Logger.verifyEquals("未知错误，系统异常|未知错误，系统异常", getuserwillexpirecouponcountCall.getMessage(), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserWillExpireCouponCount_008() {
		Logger.start(true,"获取用户即将过期的优惠券数量-lastUserId不存在");
		try {
			
			getuserwillexpirecouponcountBean.setDays(10);
			getuserwillexpirecouponcountBean.setPageSize(11);
			getuserwillexpirecouponcountBean.setLastUserId(111111);
			
			getuserwillexpirecouponcountCall.setData(getuserwillexpirecouponcountBean);
			getuserwillexpirecouponcountCall.callService();		
		
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	private void verifyReturn()
	{
		Logger.verifyEquals("0", getuserwillexpirecouponcountCall.getCode(), "验证返回code");
		Logger.verifyEquals("操作成功！", getuserwillexpirecouponcountCall.getMessage(), "验证返回Message");
	
		List<Map> result = new YmtCouponBatchWapper().getUserWillExpireCouponCount(getuserwillexpirecouponcountBean.getPageSize(),getuserwillexpirecouponcountBean.getDays(),getuserwillexpirecouponcountBean.getLastUserId());
		
		List<CouponCount> couponCountList = getuserwillexpirecouponcountCall.getCouponCountList().getCouponCountList();
		
		Logger.verifyEquals(result.size(), couponCountList.size(), "验证返回code");
		
		for(int i=0;i<couponCountList.size();i++)
		{
			CouponCount couponCount = couponCountList.get(i);
			
			Logger.verifyEquals(Integer.parseInt(result.get(i).get("UserId").toString()), couponCount.getUserId(), "验证返回UserId");
			Logger.verifyEquals(Integer.parseInt(result.get(i).get("CouponCount").toString()), couponCount.getCouponCount(), "验证返回CouponCount");

		}
	}
}